package com.yimi.yinhepda.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.yimi.yinhepda.R;
import com.yimi.yinhepda.entity.DifferScanEntity;
import java.util.HashMap;
import java.util.List;

/**
 * 项目名称：YinHePda
 * 创建时间：2017/3/8 15:18
 * 版本号：1.0
 * 功能描述
 *
 * @author 刘宏恩
 */
public class DifferScanAdapter extends BaseAdapter {
  LayoutInflater inflater;
  List<HashMap<String, Object>> dataList;
  private static final int TYPE_DEFOUT = 1;
  private static final int TYPE_RED = 2;
  private static final int TYPE_GREEN = 3;
  private Context context;

  public DifferScanAdapter(Context context, List<HashMap<String, Object>> dataList) {
    this.context = context;
    this.dataList = dataList;
    this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  }

  @Override public int getCount() {
    return null != dataList ? dataList.size() : 0;
  }

  @Override public View getView(int position, View convertView, ViewGroup arg2) {
    int type = (Integer) dataList.get(position).get("type");
    DifferScanEntity item = (DifferScanEntity) dataList.get(position).get("waybill");
    ViewHolder holder = null;
    if (convertView == null) {
      holder = new ViewHolder();
      convertView = inflater.inflate(R.layout.load_scan_item2, null);
      // 运单号
      holder.waybillnum = (TextView) convertView.findViewById(R.id.text1);
      //包装
      holder.packaging = (TextView) convertView.findViewById(R.id.text2);
      //少货
      holder.missingNums = (TextView) convertView.findViewById(R.id.text3);
      // 已扫
      holder.scaned = (TextView) convertView.findViewById(R.id.text4);
      // 差异
      holder.differ = (TextView) convertView.findViewById(R.id.text5);
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }
    // 运单号
    holder.waybillnum.setText(item.getWaybillNo());
    //包装
    holder.packaging.setText(item.getPackageName());
    //少货
    holder.missingNums.setText(item.getMissingBills().size());
    // 已扫
    holder.scaned.setText(item.getScanedWaybills().size());
    // 差异
    holder.differ.setText(item.getDifferNum() + "");
    switch (type) {
      case TYPE_DEFOUT:
        convertView.setBackgroundColor(context.getResources().getColor(R.color.white));
        break;
      case TYPE_RED:
        convertView.setBackgroundColor(context.getResources().getColor(R.color.red));
        break;
      case TYPE_GREEN:
        convertView.setBackgroundColor(context.getResources().getColor(R.color.green));
        break;
      default:
        break;
    }

    return convertView;
  }

  static class ViewHolder {
    /** 运单号 */
    TextView waybillnum;
    /** 包装 */
    TextView packaging;
    /** 少货 */
    TextView missingNums;
    /** 已扫 */
    TextView scaned;
    /** 差异 */
    TextView differ;
  }

  @Override public Object getItem(int position) {
    // TODO 自动生成的方法存根
    return null;
  }

  @Override public long getItemId(int position) {
    // TODO 自动生成的方法存根
    return 0;
  }
}
